<template>
  <div>
    <h2>问题：{{rowData.title}}</h2>
    <p class="p-desc">编辑答案内容：</p>
    <VueUEditor @on-content="getContentHander"></VueUEditor>
    <div class="btn-box">
      <Button  @click="updateAnswer" type="success" long size="large">保存编辑</Button>
    </div>
  </div>
</template>


<script>
  import VueUEditor from "dm-vue-ueditor";
  import Utils from 'dm-dev-utils';
  import API from '../../api/api_interview';
  export default {
    data () {
      return {
        rowData:{},
        editor : null,
        timer: null
      }
    },
    components: {
      VueUEditor
    },
    created () {
      
    },
    methods: {
      getContentHander(editor){
        // console.log(7777,editor.isReady);
        this.editor = editor;
      }
      ,
      getContent(){
        
      },
      _isReady(){
        return this.editor && this.editor.isReady === 1 ? true:false;
      },
      updateAnswer(){
        let content = this.editor.getContent();
        if(content === ""){
          this.$Message.error("答案内容不能为空！！！");
          return;
        }
        let params = {
          consult_text:content
        }

        API.update(this.rowData.id, params).then((res)=>{
          this.$Message.success( '编辑答案成功' );
        })
      },
      _getAnswerById(id){
        // API.findById(id).then((res)=>{
            
        // });
      }
    },
    created () {
      this.rowData = JSON.parse(localStorage.getItem('editRow'));
    },
    mounted () {
      this.timer = setInterval(()=>{
          let res = this._isReady();
          if(res){
            // console.log(this.editor.isReady);
            console.log(99999999999999);
            this.editor.setContent(this.rowData.consult_text);
            clearInterval(this.timer);
          }
      },30)
      // console.log(9999,this.editor.isReady);
      // setTimeout(() => {
      //    console.log(8888,this.editor.isReady);
      // }, 2000);
      // console.log(this.editor,9999);
      // setTimeout(() => {
      //   console.log(222,this.editor,this.rowData.consult_text);
      //   this.editor.setContent(this.rowData.consult_text);
      // }, 2000);
      
      // this.editor.setContent(11111);
      // this.editor.setContent(this.rowData.consult_text);
    }
  }
</script>

<style scoped>
h2{
  padding:20px 0px 20px 20px;
  background:#fff;
}
.p-desc{
  background:#fff;
  font-size: 18px;
  padding-left:10px;
}
.btn-box{
  padding:20px 100px;
}
</style>